<?php

namespace app\api\controller\v1;

use app\common\model\Banner as BannerModel;
use app\common\model\Casus as CasusModel;
use app\common\model\Classify as ClassifyModel;
use app\common\model\Listing as ListingModel;
use app\common\model\Dynamic as DynamicModel;
use app\common\model\Video as VideoModel;

class Index extends BaseController
{
    //曹文娜
    //首页
    public function index()
    {
        //banner图
        $model = new BannerModel();
        $banner = $model
            ->where('type', 1)
            ->field('id,image')
            ->select()
            ->toArray();
        $banner = addWebSiteUrl($banner, ['image']);
        //首页分类
        $classifyModel = new ClassifyModel();
        $list = $classifyModel
            ->field('id,title')
            ->select()
            ->toArray();
        //分类列表
        $id = input('classify_id');
        if (empty($id)) {
            return errMsg(402, '请传分类id！');
        }
        $Listingmodel = new ListingModel();
        $listing = $Listingmodel
            ->where('classify_id', $id)
            ->field('id,image,title,content')
            ->select()
            ->toArray();
        $listing = addWebSiteUrl($listing, ['image']);
        //整形案例
        $Casusmodel = new CasusModel();
        $casus = $Casusmodel
            ->where('type', 1)
            ->field('id,image,name,desc')
            ->limit(0, 4)
            ->select()
            ->toArray();
        $casus = addWebSiteUrl($casus, ['image']);
        //医院环境左图
        $BannerModel = new BannerModel();
        $ban = $BannerModel
            ->where('type', 2)
            ->field('id,image')
            ->select()
            ->toArray();
        $ban = addWebSiteUrl($ban, ['image']);
        //医院环境
        $DynamicModel = new DynamicModel();
        $dynamic = $DynamicModel
            ->where('type', 1)
            ->field('id,image,title,content')
            ->select()
            ->toArray();
        $dynamic = addWebSiteUrl($dynamic, ['image']);
        //资讯动态上
        $DynamicModel = new DynamicModel();
        $dyn = $DynamicModel
            ->where('type', 2)
            ->field('id,image,title,content')
            ->select()
            ->toArray();
        $dyn = addWebSiteUrl($dyn, ['image']);
        //资讯动态下
        $DynamicModel = new DynamicModel();
        $dynam = $DynamicModel
            ->where('type', 5)
            ->field('id,image,title,content')
            ->select()
            ->toArray();
        $dynam = addWebSiteUrl($dynam, ['image']);
        //视频新闻
        $VideoModel = new VideoModel();
        $video = $VideoModel
            ->field('id,video')
            ->select()
            ->toArray();
        $video = addWebSiteUrl($video, ['video']);
        return sucessMsg(200, '获取成功！',
            [
                'banner' => $banner,
                'list' => $list,
                'listing' => $listing,
                'casus' => $casus,
                'ban' => $ban,
                'dynamic' => $dynamic,
                'dyn' => $dyn,
                'dynam' => $dynam,
                'video' => $video,
            ]);
    }
}
